/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package appClientHandler;


import entities.Account;
import sessions.AccountFacadeLocal;

import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.ejb.Remove;
import javax.ejb.Stateful;

/**
 *
 * eCOM - Adopte un Presta - Mars-Avril 2013
 * @author Kheira, Jef, William, Tuan-Long
 */
@Stateful(mappedName="AUPCustomerBean")
@TransactionManagement(TransactionManagementType.BEAN)
@Remote(AUPCustomerRemote.class)
public class AUPCustomerBean extends AbstractAUPBean implements AUPCustomerRemote 
{
	@EJB
	private AccountFacadeLocal accountFacade;
	private LoginResult loginResult = LoginResult.ERROR;
        
        @Override
	public void authenticate(String login, String password)
        {
            Account customer = this.accountFacade.authenticate(login, password);
		
            if (customer != null) 
            {
                loginResult = new LoginResult("", LoginResultCode.SUCCESS, 
                                new LoginIdentity(customer));
            } 
            else 
            {
                loginResult = new LoginResult("Nom d'utilisateur ou mot de passe incorrect", 
                            LoginResultCode.INVALID_CREDENTIALS, null);
            }
	}

	@Override
	public LoginResult getLoginResult() 
        {
		return this.loginResult;
	}
        
        @Remove
        @Override
        public void removeBean()
        {
            // Vide.
        }


}
